package com.yequan.thread.deadlock;

public class DeadLockDemo {

    private static String A="a";
    private static String B="b";

    public static void main(String[] args) {
        new DeadLockDemo().deadLock();
    }

    private void deadLock(){
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (A){
                    try {
                        Thread.currentThread().sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (B){
                        System.out.println("111111");
                    }
                }
            }
        });

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (B){
                    synchronized (A){
                        System.out.println("222222");
                    }
                }
            }
        });

        threadA.setName("TA");
        threadB.setName("TB");
        threadA.start();
        threadB.start();
    }

}
